
package ch.hearc.coursJava.GUI.j2D.tableAnimerHSB.j2d;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import ch.hearc.coursJava.GUI.j2D.tableAnimerHSB.settings.ImageHSBSettings;
import ch.hearc.coursJava.GUI.j2D.tableAnimerHSB.settings.Settings;

public class ImageHSB
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/

	public ImageHSB(Settings settings)
		{
		this.settings = settings.getImageHsbSettings();

		this.createImage();
		this.fillImage(settings.getPanelDessinSettings().getHue());
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	public void fillImage(double hueInit)
		{
		float hue01 = (float)hueInit;
		float dh = 1 / (float)settings.getHeight();

		for(int i = 0; i < settings.getHeight(); i++)
			{
			int color = Color.HSBtoRGB(hue01, 1, 1);

			for(int j = 0; j < settings.getWidth(); j++)
				{
				this.image.setRGB(j, i, color);
				}

			hue01 += dh;
			}
		}

	public void dessiner(Graphics2D g2d)
		{
		g2d.drawImage(this.image, -settings.getWidth() / 2, -settings.getHeight() / 2, settings.getWidth(), settings.getHeight(), null);
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	private void createImage()
		{
		this.image = new BufferedImage(settings.getWidth(), settings.getHeight(), BufferedImage.TYPE_INT_RGB);
		}

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/

	// Input
	private ImageHSBSettings settings;

	// Tools
	private BufferedImage image;
	}
